package com.zmj.framework.response;

public enum ResponseCode {
    SUCCESS(200, "success"),
    FAIL(500, "fail"),
    BAD_REQUEST(400,"错误的请求"),
    UNAUTHORIZED(401,"身份认证失败"),
    FORBIDDEN(403,"无权限"),
    NOT_FOUND(404,"未找到对应的接口"),
    CLIENT_NOT_FOUND(420,"应用未注册"),
    CLIENTID_OR_SECRET_ERROR(421,"应用编码或秘钥错误"),
    ACCOUNT_NOT_FOUND(422,"无用户"),
    BAD_CREDENTIALS(423,"用户名或密码错误"),
    ACCOUNT_DISABLED(424,"用户禁用"),
    ACCOUNT_EXPIRED(425,"用户过期"),
    ACCOUNT_LOCKED(426,"用户锁定"),
    ACCOUNT_FIRST_LOGIN(427,"第一次登录修改密码"),
    REQUEST_PARAMETERS_ERROR(430,"请求参数校验错误"),
    INTERNAL_SERVER_ERROR(500,"服务器内部错误"),
    BAD_GATEWAY(502,"错误网关"),
    SERVICE_UNAVAILABLE(503,"服务不可用"),
    GATEWAY_TIME_OUT(504,"网关超时"),
    MIDDLEWARE_ERROR(600,"中间件异常"),
    SQL_ERROR(610,"数据库错误"),
    NO_SQL_ERROR(620,"缓存库错误"),
    MQ_ERROR(630,"消息队列错误"),
    OTHER_MIDDLEWARE_ERROR(690,"其他中间件异常"),
    REMOTE_ERROR(700,"远程调用异常"),
    REMOTE_TIME_OUT(701,"远程服务调用超时"),
    REMOTE_AUTHORITY_ERROR(702,"远程服务认证失败"),
    REMOTE_SERVICE_ERROR(703,"远程服务异常响应码"),
    LIMIT_ERROR(800,"限流"),
    THE_HIT_LIST(801,"黑名单"),
    LIMIT(802,"触发限流"),
    REPEAT(803,"重复请求"),
    BUSINESS_ERROR(900,"业务异常"),
    REPEAT_DATA(901,"重复数据"),
    UNAVAILABLE_DATA(902,"当前数据不可用"),
    FORBIDDEN_DATA(903,"禁止操作数据");

    ResponseCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private int code;
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static ResponseCode fromCode(int code) {
        try {
            ResponseCode[] rcs = ResponseCode.values();
            for (ResponseCode rc : rcs) {
                if (rc.getCode() == code) {
                    return rc;
                }
            }
        } catch (Exception e) {
        }
        return null;
    }
}
